#!/usr/bin/python

# Written by Yevgeniy Medynskiy (eugenem@gatech.edu)
# Date modified: December 2006
#
# No copyright. No warranty. Distributed as-is.
#
# http://www.gvu.gatech.edu/ccg/resources/wearableRFID.html

import time
import bluetooth

#
## Change to your device's Bluetooth address
#
#device = "00:13:E0:38:8B:A1"

port = 1

#
## Read command and request for acknowledgement.
#
cmd1 = "\x72\x65\x33\x36\x34\x02\x07\x01"
cmd2 = "\x61\x63\x6B\x6E\x77\x6C\x67\x65"

socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)

print "Attempting to connect to " + device + ":" + str(port) + "...",
socket.connect((device, port))
print "done."

socket.send(cmd1)
socket.send(cmd2)

print "Receiving data..."

data = ""
try:
    while True:
        try:
            data = socket.recv(255)
        except bluetooth.BluetoothError, b:
            print "Bluetooth Error: ", b

        if len(data) > 0: print data
except KeyboardInterrupt:
    print "Closing socket...",
    socket.close()
    print "done."
